﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using NLog;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace AirlineCommon
{
    public class Sector
    {
        //private const string CONNECTION_STRING = "AirlineConnectionString";
        private string _sectorID;

        public string SectorID
        {
            get { return _sectorID; }
            set { _sectorID = value; }
        }
        private string _Description;

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }
        private float _FirstClassFare;

        public float FirstClassFare
        {
            get { return _FirstClassFare; }
            set { _FirstClassFare = value; }
        }
        private float _BusinessClassFare;

        public float BusinessClassFare
        {
            get { return _BusinessClassFare; }
            set { _BusinessClassFare = value; }
        }
        private float _EconomyClassFare;

        public float EconomyClassFare
        {
            get { return _EconomyClassFare; }
            set { _EconomyClassFare = value; }
        }
        private string _WeekDay1;

        public string WeekDay1
        {
            get { return _WeekDay1; }
            set { _WeekDay1 = value; }
        }
        private string _WeekDay2;

        public string WeekDay2
        {
            get { return _WeekDay2; }
            set { _WeekDay2 = value; }
        }
        public Sector GetSectorDetail(string description)
        {
            string strCONN = DAL.DatabaseProvider.AirlineConnectionString;
            string sql = "Select SectorID, Description, WeekDay1, WeekDay2, FirstClassFare, BusinessClassFare, EconomyClassFare from  Sector where Description=@Description";
            try
            {
                SqlParameter pDesc=new SqlParameter ("@Description",description );
                DataSet ds = SqlHelper.ExecuteDataset(strCONN, CommandType.Text, sql, pDesc);

                DataRow dr= ds.Tables[0].Rows[0];
                _sectorID = dr[0].ToString();
                _Description =dr[1].ToString ();
                _WeekDay1 = dr[2].ToString();
                _WeekDay2 = dr[3].ToString();
                _FirstClassFare =float .Parse ( dr[4].ToString());
                _BusinessClassFare = float.Parse(dr[5].ToString());
                _EconomyClassFare = float.Parse(dr[6].ToString());
                return this;
            }
            catch (Exception ex)
            {
                //Log Exception (will be provided in next release)
                AppLogger.Error("Error Executing in Get Sector Details", ex, "Sector", "GetSectorDetail");
                throw;
            }
        }
    }
}
